function hiddenlogbyid( ids ) 
{
   var div = document.getElementById( ids );
   if ( div == null || div == undefined ) return;
   if ( div.style.display == "" )
      div.style.display = 'none';
   else
      div.style.display = "";
}

function isidshidden( ids )
{
   var div = document.getElementById( ids );
   if ( div == null || div.style.display == "none" )
      return true;
   else
      return false;
}

function hididallways( ids )
{
    if ( !isidshidden( ids ) )
         hiddenlogbyid( ids );
}

function hd258()
{
    var ids = new Array( 
         "diva",
         "dive",
         "divc",
         "divx",
         "divp",
         "divf",
         "divb"
    );

    for ( var i=0; i<ids.length; i++ )
       hididallways( ids[i] );

}

function repaintbottom258()
{
        var sz = getQueryString("p");
        if (sz != null && sz == "258" )
        {
//            g_col = parseInt(sz);
//            g_row = g_col + 2;

            var halfblank = parseInt(parseInt(g_col/2)/2);
            var halfw = parseInt(g_col/2) - halfblank;

            var idx = 0;
            for ( var i=0; i<halfblank; i++ )
            {    deleteChess(g_row -1, idx, false); // chesspos += '0';
//                 deleteChess(g_row/2 -1, idx, false); // chesspos += '0';
                 idx++;
            }
            for ( i=0; i<halfw /*-2*/; i++ )
            {
    if (matrix[g_row -1][idx] == null)
    {            matrix[g_row -1][idx] = createChessOne(g_row -1, idx, 'z'); // chesspos += 'z';
//                 matrix[g_row/2 -1][idx] = createChessOne(g_row/2 -1, idx, 'z'); // chesspos += 'z';
    }
                idx ++;
            }

            if ( parseInt(g_col/2) != g_col/2 )
            {    deleteChess(g_row -1, idx, false); // chesspos += '0';
//                 deleteChess(g_row/2 -1, idx, false); // chesspos += '0';
                 idx ++;
            }

            for ( i=0; i<halfw /*-2*/; i++ )
            {
    if (matrix[g_row -1][idx] == null)
    {            matrix[g_row -1][idx] = createChessOne(g_row -1, idx, 'Z'); // chesspos += 'z';
//                 matrix[g_row/2 -1][idx] = createChessOne(g_row/2 -1, idx, 'Z'); // chesspos += 'z';
    }            idx ++;
            }
            for ( i=0; i<halfblank; i++ )
            {    deleteChess(g_row -1, idx, false); // chesspos += '0';
//                 deleteChess(g_row/2 -1, idx, false); // chesspos += '0';
                 idx++;
            }

            return;
        } 

}

function afterMoveChessTo258( pos, clr )
{
    syncMid258( prepos, clr );
    syncMid258( pos, clr );

    repaintbottom258();
}

var g_leftMirrleNum = 8;
var g_rightMirrleNum = 8;

function inMidLeft258( pos )
{
    var top = new Array( 
         1,1, 3,1, 5,1,
         1,3,       5,3,
         1,5, 3,5, 5,5
    );
    for ( var i=0; i<top.length; i+=2 )
        if ( pos.c == top[i] &&
             pos.r == top[i+1] ) return true;
    return false;
}

function inMidRight258( pos )
{
    var top = new Array( 
         8,1, 10,1, 12,1,
         8,3,       12,3,
         8,5, 10,5, 12,5
    );
    for ( var i=0; i<top.length; i+=2 )
        if ( pos.c == top[i] &&
             pos.r == top[i+1] ) return true;
    return false;
}

function inMid258( pos )
{
    return inMidLeft258( pos ) ||
           inMidRight258( pos );
}

function mirrleMid258( pos, bottom, clr )
{
            if ( matrix[pos.r][pos.c] != null )
            {   // create the bottom.
                clr = matrix[pos.r][pos.c].color;
                if ( matrix[bottom.r][bottom.c] == null ) {
                    // create.
                    matrix[bottom.r][bottom.c] = createChessOne( bottom.r, bottom.c, clr=='r'?'z':'Z' );
                    if ( clr == 'r' )
                        g_leftMirrleNum --;
                    else
                        g_rightMirrleNum --;
                }
            } else {
                // delete the bottom.
                if ( matrix[bottom.r][bottom.c] != null ) {
                    clr = matrix[bottom.r][bottom.c].color;
                    deleteChess( bottom.r, bottom.c, false );
                    if ( clr == 'r' )
                        g_leftMirrleNum ++;
                    else
                        g_rightMirrleNum ++;
                }
            }            
}

function syncMid258( pos, clr )
{
    if ( inMid258( pos ) )
    {
        if ( inMidLeft258( pos ) )
        {    // top.
            var right = { r:pos.r, c:pos.c+7 };
            mirrleMid258( pos, right, clr );
        } else {
             // bottom.
            var left = { r:pos.r, c:pos.c-7 };
            mirrleMid258( pos, left, clr );
        }
    }
}


function repaintbottom258()
{
    deleteChess( g_row-1, 6, false );
    deleteChess( g_row-2, 6, false );
    deleteChess( g_row-3, 6, false );
    deleteChess( g_row-4, 6, false );

    repaintLeftMirrle();

    deleteChess( g_row-1, g_col-7, false );
    deleteChess( g_row-2, g_col-7, false );
    deleteChess( g_row-3, g_col-7, false );
    deleteChess( g_row-4, g_col-7, false );

    repaintRightMirrle();
}

function repaintLeftMirrle()
{
    for ( var i=0; i<8; i++ )
    {
        var ln = parseInt(i/2);
        if ( g_leftMirrleNum > i ) {
            if ( matrix[g_row-(1+ln)][1-(i-ln*2)] == null )
                matrix[g_row-(1+ln)][1-(i-ln*2)] = createChessOne( g_row-(1+ln), (1-(i-ln*2)), 'z', 0.56 );
        } else deleteChess( g_row-(1+ln), (1-(i-ln*2)), false );
    }
}

function repaintRightMirrle()
{
    for ( var i=0; i<8; i++ )
    {
        var ln = parseInt(i/2);
        if ( g_rightMirrleNum > i ) {
            if ( matrix[g_row-(1+ln)][g_col-1-(1-(i-ln*2))] == null )
                matrix[g_row-(1+ln)][g_col-1-(1-(i-ln*2))] = createChessOne( g_row-(1+ln), (g_col-1-(1-(i-ln*2))), 'Z', 0.69 );
        } else deleteChess( g_row-(1+ln), (g_col-1-(1-(i-ln*2))), false );
    }
}
